# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
        visited_set = set()
        while headA or headB:
            tmp1 = headA
            visited_set.add(tmp1)
            if headB in visited_set:
                return headB

            tmp2 = headB
            visited_set.add(tmp2)
            if headA in visited_set:
                return headA

            if headA:
                headA = headA.next
            if headB:
                headB = headB.next
from operator import add, sub, mul


[
    [5],
    [2,7],
    [1,3,4,None]
 ]